from django.http import JsonResponse
from django.views import View

"""
1.继承 定义类视图需要继承自Django提供的父类View
2. url 配置路由时，使用类视图的as_view()方法来添加
"""

class ClassView(View):
    def get(self, request):
        data = {'message': 'This is a GET request.'}
        return JsonResponse(data)

    def post(self, request):
        data = {'message': 'This is a POST request.'}
        return JsonResponse(data)
